<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>更新时的一个问题</title>
    <!-- 引入Vue -->
    <script type="text/javascript" src="../js/vue.js"></script>
</head>
<body>
    <!-- 准备好一个容器 -->
    <div id="root">
        <!-- 数组遍历 -->
        <h2>人员列表</h2>
        <button type="button" @click="updateMei">修改马冬梅信息</button>
        <ul>
            <!-- for in行  for of报错 -->
            <li v-for="(p, index) in persons" :key="index">
                {{p.name}} - {{p.age}} - {{p.sex}}
            </li>
        </ul>
    </div>
</body>

<script type="text/javascript">
    Vue.config.productionTip = false;   // 阻止vue 在启动时生成生产提示

    const vm = new Vue({
        el: "#root",
        data: {
            persons: [
                {
                    id: 1,
                    name: "马冬梅",
                    age: 28,
                    sex: '女'
                },
                {
                    id: 2,
                    name: "周冬雨",
                    age: 21,
                    sex: '女'
                },
                {
                    id: 3,
                    name: "周杰伦",
                    age: 32,
                    sex: '男'
                },
                {
                    id: 3,
                    name: "温兆伦",
                    age: 40,
                    sex: '男'
                }
            ]
        },
        methods: {
            updateMei() {
                // this.persons[0].name = "马老师";     // 奏效
                // this.persons[0].age = "50";      // 奏效
                // this.persons[0].sex = "男";      // 奏效

                // 直接替换对象  不奏效
                this.persons[0] = {
                    id: 1,
                    name: "马老师",
                    age: 50,
                    sex: '男'
                }
            }
        },
    })

    console.log(vm.persons[0]);
</script>
</html>